package com.bydq.patrolsystem.handler;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

//mp的自动字段填充插件
@Component
public class MyFillHanlder implements MetaObjectHandler {

    // 插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("creationTime",new Date(),metaObject);
        this.setFieldValByName("lastUpdateTime",new Date(),metaObject);
        //默认的密码为123456
        this.setFieldValByName("userPassword","123456",metaObject);
    }


    // 更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("lastUpdateTime",new Date(),metaObject);
    }
}
